import { useEffect, useState } from 'react';

const URL = 'http://geek.itheima.net/v1_0/channels';

export default function UseEffectTest(props) {
  const [tableList, setTableList] = useState([])
  const [count, setCount] = useState(0)
  
  useEffect(() => {
    async function getList() {
      const res = await fetch(URL)
      const listRes = await res.json()
      setTableList(listRes.data.channels)
    }
    getList()
  }, [])

  const handleDianjiClick = () => {
    setCount(count + 1)
  }

  useEffect(() => {
    console.log(count)
  },[count])

  return (
    <div>
      {
        tableList.map((item) => {
          return (
            <div key={item.id}>
              {item.name}
            </div>
          )
        })
      }
      <button onClick={handleDianjiClick}>电击 {count}</button>
    </div>
  )
}